package Concurrent;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * Description：
 * Author: zhangc
 * Date：2017/8/16 14:16
 */
public class CallableFuture {

    public static void main(String[] args) {

        Callable<String> callable = () -> {
            Thread.sleep(20000);
            return "zhangchao";
        };

        FutureTask<String> future = new FutureTask<String>(callable);

        new Thread(future).start();

//        try {
//            Thread.sleep(2000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        System.out.println("===================");
        try {
            System.out.println(future.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        System.out.println("========================");
    }

}
